<?php
$cs=Yii::app()->clientScript;
$cs->registerScript('consignor_info',<<<END
function make_name(info){
	$(info).each(function(i,item){
		$(item).find("input[type!=button]").each(function(n,obj){
			var re=/\d{1,10}/g;
			obj.name=obj.name.replace(re,String(i));
		});
	});
}
var info_n=100;
function info(main,info,add_btn,del_btn){
	this.main=main;
	this.info=info;
	this.init=function(){\$(add_btn).click(this.add_info);$(del_btn).click(this.del_info);}
	this.add_info=function(){
		info_n+=1
		var f=$(".linkman_info_temp:first").clone(true);f.attr('class','linkman_info').show();
		f.find("input[type!=button]").val('').removeClass('error')
		.each(
			function(i,obj){
				var re=/\d{1,10}/g;
				obj.id=obj.id.replace(re,info_n);
			}
		);
		f.find("span[class=error]").remove();
		f.appendTo(main);
		make_name(info);
	}
	this.del_info=function(){
		//if($(info).length<2) return;
		$(this).parents(info).remove();
		make_name(info);
	}
}
var t=new info("#main",".linkman_info","#add_linkman",'.del_linkman');
t.init();
END
);
?>
<div class="yiiForm">
<?php
	echo EHtml::form();	
	EHtml::setOptions(array('errorElement'=> 'span',));		
?>
<div>注：<span class="required">*</span>为必填项</div>
<div id="leftaa">
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'name'); ?>
<?php echo EHtml::activeTextField($model,'name',array('size'=>8,'maxlength'=>100)); ?>
</div>
<div class="simple1">
<?php echo CHtml::activeLabelEx($model,'legal_person_name'); ?>
<?php echo EHtml::activeTextField($model,'legal_person_name',array('size'=>8,'maxlength'=>30)); ?>
</div>
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'office_tel'); ?>
<?php echo EHtml::activeTextField($model,'office_tel',array('size'=>16,'maxlength'=>25)); ?>
</div>
<div class="simple1">
<?php echo CHtml::activeLabelEx($model,'office_fax'); ?>
<?php echo EHtml::activeTextField($model,'office_fax',array('size'=>16,'maxlength'=>25)); ?>
</div>
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'registered_address'); ?>
<?php echo EHtml::activeTextField($model,'registered_address',array('size'=>20,'maxlength'=>100)); ?>
</div>
<div class="simple1" style="margin-bottom:-1px;">
<?php echo CHtml::activeLabelEx($model,'registered_capital'); ?>
<?php echo EHtml::activeTextField($model,'registered_capital',array('size'=>8,)); ?>
</div>
</div>
  <div id="rightaa">
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'nature'); ?>
<?php echo EHtml::activeTextField($model,'nature',array('size'=>20,'maxlength'=>30)); ?>
</div>
<div class="simple1">
<?php echo CHtml::activeLabelEx($model,'storage_manager'); ?>
<?php echo EHtml::activeTextField($model,'storage_manager',array('size'=>8,'maxlength'=>30)); ?>
</div>
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'dispatcher'); ?>
<?php echo EHtml::activeTextField($model,'dispatcher',array('size'=>8,'maxlength'=>30)); ?>
</div>
<div class="simple1">
<?php echo CHtml::activeLabelEx($model,'reckoner'); ?>
<?php echo EHtml::activeTextField($model,'reckoner',array('size'=>8,'maxlength'=>30)); ?>
</div>
<div class="simple">
<?php echo CHtml::activeLabelEx($model,'term'); ?>
<?php echo EHtml::activeTextField($model,'term',array('size'=>8,'maxlength'=>10,"id"=>"term",)); ?>
<?php $this->widget('application.extensions.calendar.SCalendar',array('inputField'=>'term','ifFormat'=>'%Y-%m-%d',));?>
</div>
<div class="simple1" style="margin-bottom:-1px;">
</div>
</div>

<div  style="border:1px solid #90b3bc;border-top:0px;">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input id="add_linkman" type="button" value="添加装货地"/>
</div>

<div id="main" >
<?php
	foreach($linkman_models as $n=>$linkman_model):
?>
<table class="linkman_info" width="100%"   border="0"   cellpadding="0"   cellspacing="0"   bgcolor="#90b3bc">
<tr>
<td width="122"  bgcolor="#ffffff" align="right" height="30">&nbsp;&nbsp;<?php echo CHtml::activeLabelEx($linkman_model,'name'); ?></td>
<td  bgcolor="#ffffff">&nbsp;&nbsp;<?php echo EHtml::activeTextField($linkman_model,'name',array('class'=>'required','name'=>"linkman[{$n}][name]",'size'=>8,'maxlength'=>11)); ?></td>
<td bgcolor="#ffffff" align="right" height="30">&nbsp;&nbsp;<?php echo CHtml::activeLabelEx($linkman_model,'mobile_no'); ?></td>
<td  bgcolor="#ffffff">&nbsp;&nbsp;<?php echo EHtml::activeTextField($linkman_model,'mobile_no',array('class'=>'required','name'=>"linkman[{$n}][mobile_no]",'size'=>20,'maxlength'=>18)); ?></td>
</tr>
<tr>
<td bgcolor="#ebf4fb" align="right" height="30">&nbsp;&nbsp;<?php echo CHtml::activeLabelEx($linkman_model,'addr'); ?></td>
<td  bgcolor="#ebf4fb">&nbsp;&nbsp;<?php echo EHtml::activeTextField($linkman_model,'addr',array('class'=>'required','name'=>"linkman[{$n}][addr]",'size'=>40,'maxlength'=>100)); ?></td>
<td   bgcolor="#ebf4fb"><input class="del_linkman"  type="button" value="删除"/></td>
<td   bgcolor="#ebf4fb"></td>
</tr>
<tr>
<td height="1" ></td>
</tr>
</table><!--linkman_info-->
<?php 
endforeach;
?>
</div><!-- main -->
<div class="action">
<?php echo CHtml::submitButton($update ? '更新信息' : '添加信息'); ?>
</div>
<?php echo EHtml::endForm(); ?>
</div><!-- yiiForm -->


<table class="linkman_info_temp" width="100%"   border="0"   cellpadding="0"   cellspacing="0"   bgcolor="#90b3bc" style="display:none">
<tr>
<td width="122"  bgcolor="#ffffff" align="right" height="30">&nbsp;&nbsp;<?php echo CHtml::activeLabelEx($linkman_model_temp,'name'); ?></td>
<td  bgcolor="#ffffff">&nbsp;&nbsp;<?php echo EHtml::activeTextField($linkman_model_temp,'name',array('class'=>'required','name'=>"linkman[0][name]",'size'=>8,'maxlength'=>11)); ?></td>
<td bgcolor="#ffffff" align="right" height="30">&nbsp;&nbsp;<?php echo CHtml::activeLabelEx($linkman_model_temp,'mobile_no'); ?></td>
<td  bgcolor="#ffffff">&nbsp;&nbsp;<?php echo EHtml::activeTextField($linkman_model_temp,'mobile_no',array('class'=>'required','name'=>"linkman[0][mobile_no]",'size'=>20,'maxlength'=>18)); ?></td>
</tr>
<tr>
<td bgcolor="#ebf4fb" align="right" height="30">&nbsp;&nbsp;<?php echo CHtml::activeLabelEx($linkman_model_temp,'addr'); ?></td>
<td  bgcolor="#ebf4fb">&nbsp;&nbsp;<?php echo EHtml::activeTextField($linkman_model_temp,'addr',array('class'=>'required','name'=>"linkman[0][addr]",'size'=>40,'maxlength'=>100)); ?></td>
<td   bgcolor="#ebf4fb"><input class="del_linkman"  type="button" value="删除"/></td>
<td   bgcolor="#ebf4fb"></td>
</tr>
<tr>
<td height="1" ></td>
</tr>
</table><!--linkman_info-->

<?php 
if($model->hasErrors()) echo "<script>alert('您填写的信息有误！请根据页面红色图标提示修改。');</script>";
?>